//职员管理

import React, {Component} from 'react';
import app from '../app';
import {Form, Button, Row, Radio} from 'antd';
import {project, shop} from '../value';
import '../css/other.css';
import {config} from "../config";

const FormItem = Form.Item;
const RadioGroup = Radio.Group;

class OperationalSetup extends Component {
    constructor(props) {
        super(props);
        this.state = {
            goodList: [],
            allNumber: 0,
            imgUrl: ''
        }
    }

    formItemLayout = {
        labelCol: {span: 2},
        wrapperCol: {span: 12},
    };

    render() {
        const {getFieldDecorator} = this.props.form;
        return (
            <div style={{paddingBottom: 25}}>
                <div className="pageTitle">
                    店铺设置/运营设置
                </div>
                <Row style={{marginTop: 50}}>
                    <FormItem label={"是否自动接单"} style={{display: 'flex'}} {...this.formItemLayout}>
                        {getFieldDecorator('shop_receipt')(
                            <RadioGroup onChange={(e) => this.onChangeUse(e)} style={{padding: 0}}>
                                <Radio value={'1'}>自动接单</Radio>
                                <Radio value={'2'}>手动接单</Radio>
                            </RadioGroup>
                        )}
                    </FormItem>
                </Row>
            </div>
        )
    }

    /**
     * 初始化
     */
    componentDidMount() {
        this.handleSearchSetting();
    }


    /**
     * 查找店铺设置
     */
    handleSearchSetting() {
        let _this = this;
        _this.setState({loading: true});
        app.post(shop.SEARCH_SHOP, {}).then(result => {
            if (result.code === 1) {
                let shop_receipt = result.data.shop_receipt;
                let formData = [];
                formData['shop_receipt'] = {value: shop_receipt};
                _this.props.form.setFields(formData);
            } else {
                app.alert(result.msg, 'info', 1);
            }
        });
    }


    /**
     * 处理提交事件
     * @param e
     */
    onChangeUse(e) {
        console.log(e.target.value);
        e.preventDefault();
        let _this = this;
        app.post(shop.ADD_UPDATE_SHOP_OPERATE, {shop_receipt:e.target.value}).then((res) => {
            if (res.code == 1) {

            } else {
                app.alert(res.msg, 'info', 1);
            }
        })
    }

}

const OperationalSetups = Form.create()(OperationalSetup);

export default OperationalSetups


